#include "player.h"
#include "loc/loc-consts.h"
#include "loc/rva.h"

using namespace std;

bool Player::on_taxi() const { return role_.on_taxi(); }

bool Player::combating() const { return role_.combating(); }

float Player::dist_ground(std::shared_ptr<Ground> ground) const {
  return sqrt(pow(ground->x() - role_.x(), 2) +
              pow(ground->y() - role_.y(), 2) +
              pow(ground->z() - role_.z(), 2));
}

float Player::dist_unit(const Role &role) const {
  return sqrt(pow(role.x() - role_.x(), 2) + pow(role.y() - role_.y(), 2) +
              pow(role.z() - role_.z(), 2));
}

float Player::dist(float x, float y, float z) const {
  return sqrt(pow(x - role_.x(), 2) + pow(y - role_.y(), 2) +
              pow(z - role_.z(), 2));
}

float Player::x() const { return role_.x(); }

float Player::y() const { return role_.y(); }

float Player::z() const { return role_.z(); }

float Player::h() const { return role_.h(); }

float Player::v() const { return role_.v(); }

uint32 Player::hp() const { return role_.hp(); }

uint32 Player::hp_max() const { return role_.hp_max(); }

uint32 Player::mp() const { return role_.mp(); }

uint32 Player::mp_max() const { return role_.mp_max(); }

uint32 Player::level() const { return role_.level(); }

uint32 Player::casting() const { return role_.casting(); }

uint32 Player::channel() const { return role_.channel(); }

uint8 Player::backpack_num_slots() const {
  return r1(ptr() + backpack_size_offset);
}

string Player::name() const { return (char *)(base_ + RVA_PLAYER_NAME_BASE); }

uintptr Player::ptr() const { return obj_.ptr(); }

ObjType Player::type() const { return obj_.type(); }

uint32 Player::index() const { return obj_.index(); }

uint64 Player::tid1() const { return role_.tid1(); }

uint64 Player::tid2() const { return role_.tid2(); }

uint64 Player::id1() const { return obj_.id1(); }

uint64 Player::id2() const { return obj_.id2(); }

Role Player::role() const { return role_; }

Player::Player(uint64 base, uint64 ptr) : base_{base}, obj_{ptr}, role_{ptr} {}

Player::~Player() {}
